package com.ty.controller;

import com.ty.entity.Order;
import com.ty.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Api(tags = "订单信息对象功能接口")
@RestController
@RequestMapping("/order")
public class OrderController extends BaseController {

    @Autowired
    OrderService orderService;

    /**
     * 通过ID查询单条数据
     *
     * @param orderId 主键
     * @return 实例对象
     */
    @ApiOperation("通过ID查询单条数据")
    @GetMapping
    public ResponseEntity<Order> queryById(Integer orderId){
        return ResponseEntity.ok(orderService.queryById(orderId));
    }

  /*  *//**
     * 分页查询
     *
     * @param order 筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     *//*
    @ApiOperation("分页查询")
    @GetMapping
    public ResponseEntity<Page<Order>> paginQuery(Order order, PageRequest pageRequest){
        return ResponseEntity.ok(orderService.paginQuery(order, pageRequest));
    }*/

    /**
     * 新增数据
     *
     * @param order 实例对象
     * @return 实例对象
     */
   /* @ApiOperation("新增数据")
    @PostMapping
    public ResponseEntity<Order> add(Order order){
        return ResponseEntity.ok(orderService.insert(order));
    }*/

    /**
     * 更新数据
     *
     * @param order 实例对象
     * @return 实例对象
     */
    @ApiOperation("更新数据")
    @PutMapping
    public ResponseEntity<Order> edit(Order order){
        return ResponseEntity.ok(orderService.update(order));
    }

    /**
     * 通过主键删除数据
     *
     * @param orderId 主键
     * @return 是否成功
     */
    @ApiOperation("通过主键删除数据")
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer orderId){
        return ResponseEntity.ok(orderService.deleteById(orderId));
    }

   /* @Autowired
    OrderService orderService;

    @Autowired
    OrderDetailService orderDetailService;

    @Autowired
    OrderMapper orderMapper;*/

//    @GetMapping("/order")
//    public ResultBean query(){
//        String rs = String.valueOf(orderService.query());
//        return success("ok", rs);
//    }



    /*@GetMapping("/order")
    public ResultBean query(int id) {
        Order order = orderService.getById(id);
        return success("ok", order);
    }

    @GetMapping("/order/insert")
    public ResultBean insert(){
        Order order =new Order();
        order.setOrderNum("asd");
        order.setMoney(12);
        order.setStatus(1);
        boolean rs = orderService.save(order);
        return success("ok", rs);
    }

    @GetMapping("/order/delete")
    public ResultBean delete(int id){
        boolean order =orderService.removeById(id);
        return success("ok",order);
    }

    @GetMapping("/order/update")
    public ResultBean update(@RequestParam(defaultValue = "18")int id){
        Order order =new Order();
        order.setId(id);
        order.setOrderNum("ling");
        Boolean rs = orderService.updateById(order);
        return success("ok",rs);
    }

    @GetMapping("/orderdetail")
    public ResultBean insert2(){
        OrderDetail orderDetail = new OrderDetail();

        orderDetail.setPrice(1);
        orderDetail.setGoodsId(46);
        String rs = String.valueOf(orderDetailService.save(orderDetail));
        System.out.println(rs);
        return success("ok",rs);
    }

    @GetMapping("/orderdetail/update")
    public ResultBean update2(@RequestParam(defaultValue = "1") int id){
        OrderDetail orderDetail =new OrderDetail();
        orderDetail.setId(id);

        orderDetail.setNum(77);
        orderDetail.setPrice(455);
        boolean rs = orderDetailService.removeById(orderDetail);
        System.out.println(rs);
        return success("ok",rs);
    }*/

}